package com.cat.dataStructure03;

import java.util.*;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/relocate-marbles/
 * @create 2025/11/18 19:44
 * @since JDK17
 */

public class Solution88 {
    public List<Integer> relocateMarbles(int[] nums, int[] moveFrom, int[] moveTo) {
        int n = nums.length, m = moveFrom.length, k = 0;
        List<Integer> ans = new ArrayList<>();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            map.put(nums[i], 1);
        }
        for (int i = 0; i < m; i++) {
            int cnt = map.getOrDefault(moveFrom[i], 0);
            map.put(moveFrom[i], 0);
            map.merge(moveTo[i], cnt, Integer::sum);
        }
        for (var e : map.entrySet()) {
            if (e.getValue() != 0) {
                ans.add(e.getKey());
            }
        }
        ans.sort(Comparator.comparingInt(a -> a));
        return ans;
    }
}
